package com.lovi.thread_;

/**
 * 线程终止
 */
public class Test05 {
    public static void main(String[] args) throws InterruptedException {
        AA aa = new AA();
        new Thread(aa).start();
        //休眠10秒再结束
        Thread.sleep(10000);
        aa.setFlag(false);

    }
}
class AA implements Runnable{
    private boolean flag = true;
    private int count = 0;
    @Override
    public void run() {
        while (flag){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("线程名："+Thread.currentThread().getName()+"执行了:"+count++);
        }
    }

    public boolean isFlag() {
        return flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }
}
